package com.zprmb.udzt;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.graphics.Color;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.webkit.JavascriptInterface;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.tencent.smtt.export.external.interfaces.SslErrorHandler;
import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
import com.zprmb.udzt.adapter.ImageAdapter;
import com.zprmb.udzt.adapter.Index_adapter;
import com.zprmb.udzt.bean.HomeBean;
import com.zprmb.udzt.bean.HomeProduct;
import com.zprmb.udzt.bean.IndexBean;
import com.zprmb.udzt.bean.Publication;
import com.zprmb.udzt.fragment.HometFragmet;
import com.zprmb.udzt.fragment.HometFragmet.setCurrentTabByTagListener;
import com.zprmb.udzt.util.BitmapUtils;
import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.LogUtils;
import com.zprmb.udzt.util.Regular;
import com.zprmb.udzt.util.ToJSON;
import com.zprmb.udzt.util.ToastUtil;
import com.zprmb.udzt.util.VolleryUtil;
import com.zprmb.udzt.view.Mydialog;
import com.zprmb.udzt.view.NestedListView;
import com.zprmb.udzt.view.ZoomOutPageTransformer;
import com.zprmb.udzt.viewflow.CircleFlowIndicator;
import com.zprmb.udzt.viewflow.ViewFlow;
import com.zprmb.udzt.vo.RequestQueue;
import com.zprmb.udzt.vo.toolbox.Volley;

import org.json.JSONObject;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
//import com.tencent.smtt.export.external.interfaces.SslError;
//import com.tencent.smtt.export.external.interfaces.SslErrorHandler;
//import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
//import com.tencent.smtt.sdk.WebSettings;
//import com.tencent.smtt.sdk.WebView;
//import com.tencent.smtt.sdk.WebViewClient;


/**
 * 首页
 *
 * @author shenshao
 */

public class HomeActivity_BeiFen extends BaseActivity implements
        OnRefreshListener<ScrollView>, OnClickListener,
        setCurrentTabByTagListener {
    long minute = 0;
    long second = 0;
    long hour = 0;
    private CircleFlowIndicator indic;
    private ViewFlow viewFlow;// 新版图片轮播
    private ViewPager home_view_pager;
    private TextView tv_zhitou_status;
    private String iconType = "";
    private String iconLink = "";
    Mydialog mydialog;
    RelativeLayout rl_web;
    PullToRefreshScrollView sv;
    private int mCurrPos;
    private AudioManager mAudioManager;
    List<View> listview = new ArrayList<View>();
    private RequestQueue mQueue;
    private TextView fresh_title, fresh_conduct_rate, fresh_home_rateadd,
            fresh_conduct_time, fresh_conduct_investAmount;
    private TextView de_title, de_conduct_rate_up, de_conduct_rate_dwon, de_home_rateadd,
            de_conduct_time, de_conduct_investAmount;
    private LinearLayout fresh_li_jiaxi, de_li_jiaxi;
    private List<Publication> pu_list = new ArrayList<Publication>();
    private ArrayList<HomeBean> list = new ArrayList<HomeBean>();
    private TextView text;
    //	private List<HometFragmet> flist = new ArrayList<HometFragmet>();
    private NestedListView lv;
    private List<String> listtag = new ArrayList<String>();
    private LinearLayout li_info, li_safe, li_invate;
    private boolean isResume = true;
    private ImageView img_info;
    private View view_dexterty, view_fresh;
    private TextView tv_v6_productdetails_hour, tv_v6_productdetails_min, tv_v6_productdetails_second;
    private List<HomeProduct> plist = new ArrayList<HomeProduct>();
    private ImageAdapter imageAdapter;
    private Refresh refresh;
    private TextView tv_unread;
    private String name, type, loanid;
    private boolean isPause = false;
    private ImageView img_new;
    private String url;
    private LinearLayout v6_home_countdown, v6_home_clock, li_close_all;
    private List<IndexBean> listhome = new ArrayList<IndexBean>();
    ArrayList<String> linkUrlArray = new ArrayList<String>();
    ArrayList<String> titleList = new ArrayList<String>();
    private String my_test;
    private RelativeLayout notice_parent_ll;
    private LinearLayout notice_ll;
    private ViewFlipper notice_vf;
    private TextView img_pl_reward;
    private ImageView iv_test, img_invest, img_left, img_right, img_test,
            iv_lottery;
    private LinearLayout li_lottery, li_operation;
    int page = 0;
    private HomeWebView homeWebView;
    private String page_url, tabFlag;
    private ImageView img_list_status, img_safe;
    private LinearLayout li_caozuo;
    private TextView platform_regist_num, platform_day, platform_total_amount;
    private Index_adapter index_adapter;
    private ArrayAdapter<String> mAdapter;
    TimerTask timerTask;
    private Timer timer;
    private TextView tv_home_zhi_tab, tv_home_list_tab;
    private TextView test_lottery, tv_info_invate, tv_info_safe, test_te;
    private DecimalFormat df = new DecimalFormat("###0.00");
    private int text_status_color = Color.parseColor("#333333");

    private TextView text_dikou;
    @SuppressWarnings("deprecation")
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_activity);
        BbtApplication.getInstance().addActvity(this);
        initView();
        inregist();
        mQueue = Volley.newRequestQueue(this);
        // Log.e("size", pu_list.size()+"");

        imageAdapter = new ImageAdapter(this, list);

        home_view_pager.setOnPageChangeListener(new OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg0) {
                // TODO Auto-generated method stub
                page = arg0;
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                // TODO Auto-generated method stub

            }
        });

        initDate(true);

    }

    private void inregist() {
        // TODO Auto-generated method stub

        img_test.startAnimation(AnimationUtils.loadAnimation(HomeActivity_BeiFen.this,
                R.anim.set2));

    }

    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // v4_webview.onPause();
        // }

        isPause = true;
        requestAudioFocus();

    }

    private OnAudioFocusChangeListener listener = new OnAudioFocusChangeListener() {
        @Override
        public void onAudioFocusChange(int focusChange) {

            if (isPause && focusChange == AudioManager.AUDIOFOCUS_LOSS
                    && !getbannerurl().contains("Video")) {
                Log.e("web_audio", "focusChange: " + focusChange);
                requestAudioFocus();
            }
        }
    };

    private void requestAudioFocus() {
        int result = mAudioManager.requestAudioFocus(listener,
                AudioManager.STREAM_MUSIC,
                AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
        if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            Log.e("web_autio", "audio focus been granted");
        }
    }

    private void active() {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                LogUtils.e(HomeActivity_BeiFen.this, "活动" + jsonObject.toString());
                JSONObject json = jsonObject.optJSONObject("data");
                page_url = json.optString("page");
                tabFlag = json.optString("tabFlag");
//				page_url="landing/mFatherDay2017";
                // page="";
                if (page_url.length() > 1) {

                    Editor editor = getShare().edit();
                    editor.putString("page_url", page_url);
                    editor.commit();
//					Log.e("music", getShare().getBoolean("music", true) + "");
                    if (homeWebView.getVisibility() == View.INVISIBLE) {

                        homeWebView.loadUrl(Constant.URL + page_url
                                + "?app=true&token=" + getToken() + "music="
                                + getShare().getBoolean("music", true));
                        homeWebView.addJavascriptInterface(new JsInterfaces(
                                HomeActivity_BeiFen.this), "AndroidWebView");

                        sv.setVisibility(View.GONE);
                        homeWebView.setVisibility(View.VISIBLE);
                    } else {
                        homeWebView.loadUrl(Constant.URL + page_url
                                + "?app=true&token=" + getToken() + "music="
                                + getShare().getBoolean("music", true));
                    }


                } else {
                    sv.setVisibility(View.VISIBLE);
                    homeWebView.setVisibility(View.INVISIBLE);
                }
                Editor editor = getShare().edit();
                editor.putString("page_url", page_url);
                editor.putString("tabFlag", tabFlag);
                editor.commit();
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
                Log.e("失败", "失败");
                sv.setVisibility(View.VISIBLE);
                homeWebView.setVisibility(View.INVISIBLE);
            }
        };

        volleryUtil.setRequestMethod(0);
        // volleryUtil.setShow(true);
        volleryUtil.execute(HomeActivity_BeiFen.this, Constant.URL
                + "/api/doubleEleven/jumpPage", "");
    }

    public void setrefresh(Refresh refresh) {
        this.refresh = refresh;
    }

    private void active_status() {
        if (Long.valueOf(ondata()) > Long.valueOf("20170122000000")
                && Long.valueOf(ondata()) < Long.valueOf("20170210111059")
                && !valentine()) {
            li_caozuo.setBackgroundResource(R.drawable.info_bg);
            text_status_color = Color.WHITE;
            iv_test.setImageBitmap(BitmapUtils.readBitMap(this,
                    R.drawable.new_year_message));
            img_safe.setImageBitmap(BitmapUtils.readBitMap(this,
                    R.drawable.new_year_safe));
            img_invest.setImageBitmap(BitmapUtils.readBitMap(this,
                    R.drawable.new_year_invate));
            iv_lottery.setImageBitmap(BitmapUtils.readBitMap(this,
                    R.drawable.new_year_lottey));

        } else {
            text_status_color = Color.parseColor("#333333");
            iv_test.setImageBitmap(BitmapUtils.readBitMap(this,
                    R.drawable.bbt_main_announcement));
            img_safe.setImageBitmap(BitmapUtils.readBitMap(this,
                    R.drawable.bbt_main_info));
            img_invest.setImageBitmap(BitmapUtils.readBitMap(this,
                    R.drawable.bbt_main_help));
            iv_lottery.setImageBitmap(BitmapUtils.readBitMap(this,
                    R.drawable.bbt_main_message));
            li_caozuo.setBackgroundColor(Color.WHITE);
        }

        test_lottery.setTextColor(text_status_color);
        test_te.setTextColor(text_status_color);
        tv_info_invate.setTextColor(text_status_color);
        tv_info_safe.setTextColor(text_status_color);
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        BbtApplication.getInstance().removeActvity(this);
    }

    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        isPause = false;
        userinfo2();
        active_status();
        active();
        lv.setFocusable(false);
//		if (getShare().getString("isHomeFirst", "").equals("")) {
//			getShare().edit().putString("isHomeFirst", "1").commit();
//			FirstDialog2 fd = new FirstDialog2(this, 1);
//			fd.show();
//		}
    }

    private void initView() {
        homeWebView = (HomeWebView) findViewById(R.id.homeWebView);
        viewFlow = (ViewFlow) findViewById(R.id.viewflow);
        indic = (CircleFlowIndicator) findViewById(R.id.viewflowindic);
        home_view_pager = (ViewPager) findViewById(R.id.home_view_pager);
        img_invest = (ImageView) findViewById(R.id.img_invate);
        sv = (PullToRefreshScrollView) findViewById(R.id.home_sv);
        lv = (NestedListView) findViewById(R.id.lv);
        tv_home_zhi_tab = (TextView) findViewById(R.id.tv_home_zhi_tab);
        tv_home_list_tab = (TextView) findViewById(R.id.tv_home_list_tab);
        de_conduct_rate_up = (TextView) findViewById(R.id.de_conduct_rate_up);
        de_conduct_rate_dwon = (TextView) findViewById(R.id.de_conduct_rate_dwon);
        de_conduct_investAmount = (TextView) findViewById(R.id.de_conduct_investAmount);
        tv_v6_productdetails_hour = (TextView) findViewById(R.id.tv_v6_productdetails_hour);
        tv_v6_productdetails_min = (TextView) findViewById(R.id.tv_v6_productdetails_min);
        tv_v6_productdetails_second = (TextView) findViewById(R.id.tv_v6_productdetails_second);
        tv_zhitou_status = (TextView) findViewById(R.id.tv_zhitou_status);
        mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        li_operation = (LinearLayout) findViewById(R.id.li_operation);
        li_caozuo = (LinearLayout) findViewById(R.id.li_caozuo);
        iv_lottery = (ImageView) findViewById(R.id.iv_lottery);
        test_lottery = (TextView) findViewById(R.id.test_lottery);
        tv_info_invate = (TextView) findViewById(R.id.tv_info_invate);
        tv_info_safe = (TextView) findViewById(R.id.tv_info_safe);
        test_te = (TextView) findViewById(R.id.test_te);
        img_safe = (ImageView) findViewById(R.id.img_safe);
        v6_home_clock = (LinearLayout) findViewById(R.id.v6_home_clock);
        v6_home_countdown = (LinearLayout) findViewById(R.id.v6_home_countdown);
        li_close_all = (LinearLayout) findViewById(R.id.li_close_all);
        text_dikou= (TextView) findViewById(R.id.text_dikou);
        Log.e("TAGGGG", plist.size() + "");
        platform_regist_num = (TextView) findViewById(R.id.platform_regist_num);
        platform_day = (TextView) findViewById(R.id.platform_day);
        platform_total_amount = (TextView) findViewById(R.id.platform_total_amount);
        li_info = (LinearLayout) findViewById(R.id.li_info);
        li_safe = (LinearLayout) findViewById(R.id.li_safe);
        li_invate = (LinearLayout) findViewById(R.id.li_invate);
        view_fresh = (View) findViewById(R.id.view_fresh);
        view_dexterty = (View) findViewById(R.id.view_dexterty);
        img_left = (ImageView) findViewById(R.id.img_left);
        img_test = (ImageView) findViewById(R.id.img_test);
        tv_unread = (TextView) findViewById(R.id.tv_unread);
        img_pl_reward = (TextView) findViewById(R.id.img_pl_reward);
        li_lottery = (LinearLayout) findViewById(R.id.li_lottery);
        img_right = (ImageView) findViewById(R.id.img_right);
        img_list_status = (ImageView) findViewById(R.id.img_list_status);
        fresh_title = (TextView) findViewById(R.id.fresh_title);
        fresh_li_jiaxi = (LinearLayout) findViewById(R.id.fresh_li_jiaxi);
        fresh_home_rateadd = (TextView) findViewById(R.id.fresh_home_rateadd);
        fresh_conduct_rate = (TextView) findViewById(R.id.fresh_conduct_rate);
        fresh_conduct_time = (TextView) findViewById(R.id.fresh_conduct_time);
        fresh_conduct_investAmount = (TextView) findViewById(R.id.fresh_conduct_investAmount);
        de_title = (TextView) findViewById(R.id.de_title);
        de_li_jiaxi = (LinearLayout) findViewById(R.id.de_li_jiaxi);
        de_home_rateadd = (TextView) findViewById(R.id.de_home_rateadd);
        de_conduct_time = (TextView) findViewById(R.id.de_conduct_time);
        iv_test = (ImageView) findViewById(R.id.iv_test);
//		sv.getLoadingLayoutProxy().setLastUpdatedLabel("lastUpdateLabel");
        sv.getLoadingLayoutProxy().setPullLabel("下拉可刷新");
        sv.getLoadingLayoutProxy().setRefreshingLabel("智慧投资 更优一点");
        sv.getLoadingLayoutProxy().setReleaseLabel("松开即刷新");

        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(HomeActivity_BeiFen.this,
                        V6DetailsActivity.class);
                intent.putExtra("name", listhome.get(position).getProductName());
                intent.putExtra("type", listhome.get(position).getProductType());
                intent.putExtra("id", listhome.get(position).getProductId());
                startActivity(intent);

            }
        });
        view_dexterty.setOnClickListener(this);
        view_fresh.setOnClickListener(this);
        li_lottery.setOnClickListener(this);
        li_info.setOnClickListener(this);
        li_safe.setOnClickListener(this);
        li_invate.setOnClickListener(this);
        img_left.setOnClickListener(this);
        li_operation.setOnClickListener(this);
        img_right.setOnClickListener(this);
        img_test.setOnClickListener(this);
        iv_test = (ImageView) findViewById(R.id.iv_test);
        sv.setOnRefreshListener(this);
        text = (TextView) findViewById(R.id.test_te);

        viewFlow.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(HomeActivity_BeiFen.this,
                        WebViewActivity.class);
                intent.putExtra("url", list.get(position).getContent());
                startActivity(intent);
            }
        });
        home_view_pager.setPageTransformer(true, new ZoomOutPageTransformer());

        // active_status();

    }

    private boolean valentine() {
        if (Long.valueOf(ondata()) > Long.valueOf("20170210111100")
                && Long.valueOf(ondata()) < Long.valueOf("20170215111159")) {
            return true;
        } else {
            return false;
        }
    }

    public void getlist() {

    }

    private void initDate(final boolean isShow) {
        VolleryUtil vollery = new VolleryUtil() {
            public void onUpDate(JSONObject jsonObject) {
                LogUtils.e(HomeActivity_BeiFen.this, "首页" + jsonObject.toString());
                JSONObject json1 = jsonObject.optJSONObject("data");
                JSONObject json2 = json1.optJSONObject("investInfo");
                JSONObject jsonfresh = json1.optJSONObject("freshProduct");
                JSONObject jsonclaim = json1.optJSONObject("intelli");

                ToJSON.initData2(jsonObject.toString(), "index");
                Gson gson = new Gson();
                Editor editor = getShare().edit();
                editor.putInt("rmb", json1.optInt("flagRmbOpen"));
                Log.e("flagRmbOpen", json1.optInt("flagRmbOpen") + "");
                editor.commit();
                if (!json1.optString("banner").equals("null")) {
                    list = gson.fromJson(json1.optString("banner"),
                            new TypeToken<ArrayList<HomeBean>>() {
                            }.getType());
                }
                iconType = json1.optString("iconType");
                iconLink = json1.optString("iconLink");
                tv_home_list_tab.setText(json1.optString("assetPrompt"));
                Log.e("iconType", iconType);
                if (!iconType.equals("")) {
                    // Log.e("iconType", iconType);
                    // img_test.setImageBitmap(BitmapUtils.readBitMap(HomeActivity.this,
                    // R.drawable.aa));
                    BbtApplication.getInstance().imageLoader.displayImage(
                            json1.optString("iconPic"), img_test);
                    //
                } else {
                    // img_test.setVisibility(View.GONE);
                }
                if (!json1.optString("publicationListNew").equals("null")) {
                    pu_list = gson.fromJson(
                            json1.optString("publicationListNew"),
                            new TypeToken<ArrayList<Publication>>() {
                            }.getType());
                }
                if (!json1.optString("mHomeProducts").equals("null")) {
                    listhome = gson.fromJson(json1.optString("mHomeProducts"),
                            new TypeToken<ArrayList<IndexBean>>() {
                            }.getType());
                }
                if (jsonfresh != null) {
                    name = jsonfresh.optString("productName");
                    type = jsonfresh.optString("productType");
                    loanid = jsonfresh.optString("productId");
                    fresh_title.setText("新手标");
                    fresh_conduct_rate.setText(Regular
                            .getDecimalFormatTwo(jsonfresh.optDouble("rate")
                                    - jsonfresh.optDouble("rateAdd")));
                    if (img_list_status.getVisibility() == View.VISIBLE) {
                        Log.e("jsonfresh",
                                jsonfresh.optString("assetLoanStatus"));
                    }
                    if (jsonfresh.optString("assetLoanStatus").equals(
                            "COLLECTING")) {
                        img_list_status.setVisibility(View.INVISIBLE);
                    } else if (jsonfresh.optString("assetLoanStatus").equals(
                            "SETTLEMENTED")) {

                        img_list_status.setVisibility(View.VISIBLE);
                        img_list_status
                                .setImageBitmap(BitmapUtils.readBitMap(
                                        HomeActivity_BeiFen.this,
                                        R.drawable.img_list_shouyiz));
                    } else if (jsonfresh.optString("assetLoanStatus").equals(
                            "REPAYED")) {
                        img_list_status.setVisibility(View.VISIBLE);
                        img_list_status.setImageBitmap(BitmapUtils.readBitMap(
                                HomeActivity_BeiFen.this,
                                R.drawable.img_list_back_money));
                    } else {
                        img_list_status.setVisibility(View.VISIBLE);
                        img_list_status.setImageBitmap(BitmapUtils.readBitMap(
                                HomeActivity_BeiFen.this, R.drawable.img_list_finsh));
                    }

                    if (jsonfresh.optInt("rateAdd") > 0) {
                        fresh_li_jiaxi.setVisibility(View.VISIBLE);
                        fresh_home_rateadd.setText(Regular
                                .getDecimalFormatTwo(jsonfresh
                                        .optDouble("rateAdd"))
                                + "%");

                    } else {
                        fresh_li_jiaxi.setVisibility(View.GONE);
                    }
                    if (jsonfresh.optBoolean("flagNowEffective")) {
                        img_pl_reward.setVisibility(View.VISIBLE);
                    } else {
                        img_pl_reward.setVisibility(View.GONE);
                    }
                    fresh_conduct_investAmount.setText(Regular
                            .getDecimalFormatTwo(jsonfresh
                                    .optDouble("remainAmount") / 10000)
                            + "万元");
                    fresh_conduct_time.setText(jsonfresh
                            .optString("productPeriod") + "天");
                } else {
                    view_fresh.setVisibility(View.GONE);
                }
                if (jsonclaim != null) {
                    de_title.setText(getResources().getString(R.string.v6_ud_dexterity));
                    de_conduct_rate_dwon.setText(Regular
                            .getDecimalFormatTwo(jsonclaim
                                    .optDouble("rateDown")));
                    de_conduct_rate_up.setText(Regular
                            .getDecimalFormatTwo(jsonclaim
                                    .optDouble("rateUp")));
                    de_conduct_time.setText(Regular
                            .getDecimalFormatZero(jsonclaim
                                    .optDouble("minAmount"))
                    );
                    de_conduct_investAmount.setText(Regular
                            .getDecimalFormatTwo(jsonclaim
                                    .optDouble("remainAmount") / 10000));
                    tv_home_zhi_tab.setText(jsonclaim.optString("intelliPrompt"));
                    if ("downCount".equals(jsonclaim.optString("intelliStatus"))) {
                        li_close_all.setVisibility(View.VISIBLE);
                        v6_home_countdown.setVisibility(View.VISIBLE);
                        tv_zhitou_status.setText("即将开放");
                        long now = jsonclaim.optLong("now");
                        long end = jsonclaim.optLong("openDate");
                        long keyong = end - now;
                        tv_zhitou_status.setBackgroundResource(R.drawable.bianqian);
                        countdwoninit(keyong);
                    } else if ("opening".equals(jsonclaim.optString("intelliStatus"))) {
                        li_close_all.setVisibility(View.GONE);
                        tv_zhitou_status.setBackgroundResource(R.drawable.bianqian);
                        tv_zhitou_status.setText("可投资");
                    } else {
                        li_close_all.setVisibility(View.VISIBLE);
                        v6_home_countdown.setVisibility(View.GONE);
                        tv_zhitou_status.setBackgroundResource(R.drawable.bianqian2);
                        tv_zhitou_status.setText("已售罄");
//						Log.e(tag, msg)
                        if (jsonclaim.optString("openTime").length() >= 5) {

                            tv_v6_productdetails_min.setText(jsonclaim.optString("openTime").substring(0, 2));
                            tv_v6_productdetails_second.setText(jsonclaim.optString("openTime").substring(3, 5));
                        }
                    }

                } else {
                    view_dexterty.setVisibility(View.GONE);
                }
                platform_day.setText(json2.optString("openDays"));
                platform_regist_num.setText(json2.optString("peoplesForRegist")
                        + "人");

                if(json2.optBoolean("flagRebate")==true){
                    text_dikou.setVisibility(View.VISIBLE);
                }else {
                    text_dikou.setVisibility(View.VISIBLE);
                }

                platform_total_amount.setText(json2.optString("investSumStr"));
                if (isShow) {
                    if (list.size() >= 1) {

                        viewFlow.setAdapter(new ImageAdapter(HomeActivity_BeiFen.this,
                                list));
                        viewFlow.setmSideBuffer(list.size()); // 实际图片张数
                        viewFlow.setFlowIndicator(indic);
                        viewFlow.setTimeSpan(4000);
                        viewFlow.setSelection(list.size() * 1000); // 设置初始位置
                        LayoutParams ll = new LayoutParams(
                                LayoutParams.WRAP_CONTENT,
                                LayoutParams.WRAP_CONTENT);
                        indic.setLayoutParams(ll);
                        viewFlow.startAutoFlowTimer(); // 启动自动播放

                    }
                }
                if (listhome != null) {

                    index_adapter = new Index_adapter(listhome,
                            HomeActivity_BeiFen.this);
                    lv.setAdapter(index_adapter);
                }


            }

            public void onError() {
                Toast.makeText(HomeActivity_BeiFen.this, "请求失败   请检查网络设置", 2000)
                        .show();
            }
        };
        vollery.setShow(true);
        vollery.setRequestMethod(0);
        // vollery.execute(this, Constant.URL + "api/v2/claim/index", "");
        vollery.execute(this, Constant.URL + "/api/v5/app/index", "");
        // Log.e("home", Constant.URL + "/api/v5/app/index");
    }

    private void initRollNotice() {
        FrameLayout main_notice = (FrameLayout) findViewById(R.id.main_notice);
        notice_parent_ll = (RelativeLayout) getLayoutInflater().inflate(
                R.layout.layout_notice, null);
        notice_ll = ((LinearLayout) this.notice_parent_ll
                .findViewById(R.id.homepage_notice_ll));
        notice_vf = ((ViewFlipper) this.notice_parent_ll
                .findViewById(R.id.homepage_notice_vf));
        img_info = (ImageView) notice_parent_ll.findViewById(R.id.img_info);
        img_info.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(HomeActivity_BeiFen.this,
                        V4WebViewActivity.class);
                intent.putExtra("url", "h5/infoList?app=true");
                intent.putExtra("title", "资讯公告");
                intent.putExtra("share", 1);
                startActivity(intent);
            }
        });
        main_notice.removeAllViews();
        main_notice.addView(notice_parent_ll);
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        moveNext();
                        Log.d("Task", "下一个");
                    }
                });

            }
        };
        if (timer == null) {

            timer = new Timer();
            timer.schedule(task, 0, 4000);
        }
    }

    private void moveNext() {
        setView(this.mCurrPos, this.mCurrPos + 1);
        this.notice_vf.setInAnimation(this, R.anim.in_bottomtop);
        this.notice_vf.setOutAnimation(this, R.anim.out_bottomtop);
        this.notice_vf.showNext();
    }

    private void setView(int curr, int next) {

        View noticeView = getLayoutInflater().inflate(R.layout.notice_item,
                null);
        TextView notice_tv = (TextView) noticeView.findViewById(R.id.notice_tv);
        img_new = (ImageView) noticeView.findViewById(R.id.img_new);

        if ((curr < next) && (next > (titleList.size() - 1))) {
            next = 0;
        } else if ((curr > next) && (next < 0)) {
            next = titleList.size() - 1;
        }
        if (pu_list.get(next).getIsNew() != null && pu_list.get(next).getIsNew()) {
            img_new.setVisibility(View.VISIBLE);

        } else {
            img_new.setVisibility(View.INVISIBLE);
        }

        notice_tv.setText(titleList.get(next));

        notice_tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(HomeActivity_BeiFen.this,
                        V4WebViewActivity.class);
                intent.putExtra("url", linkUrlArray.get(mCurrPos) + "&app=true");
                intent.putExtra("title", "资讯公告");
                intent.putExtra("share", 1);
                startActivity(intent);
            }
        });
        if (notice_vf.getChildCount() > 1) {
            notice_vf.removeViewAt(0);
        }
        notice_vf.addView(noticeView, notice_vf.getChildCount());
        mCurrPos = next;

    }

    public class MyPagerAdapter extends FragmentPagerAdapter {
        private Context context;
        private List<HometFragmet> list;
        private List<String> listt;
        private String desc;

        public MyPagerAdapter(FragmentManager fm, Context context,
                              List<HometFragmet> list, List<String> listt, String desc) {
            super(fm);
            this.context = context;
            this.list = list;
            this.listt = listt;
            this.desc = desc;
        }

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
            // TODO Auto-generated constructor stub
        }

        @Override
        public Fragment getItem(int arg0) {
            // TODO Auto-generated method stub

            // HometFragmet.newInstance(list.get(arg0),listt,desc,HomeActivity.this).setListener(HomeActivity.this);
            // return
            // HometFragmet.newInstance(list.get(arg0),listt,desc,HomeActivity.this);
            return list.get(arg0);
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return list.size();
        }

    }

    public interface Refresh {
        public void setcurrent();
    }

    private void islogin() {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    Log.e("main", jsonObject.toString());
                    JSONObject json1 = jsonObject.optJSONObject("data");
                    JSONObject json2 = json1.optJSONObject("riskData");
                    if (!jsonObject.optString("comment").equals("用户不存在")) {
                        Intent intent = new Intent(HomeActivity_BeiFen.this,
                                V4WebViewActivity.class);
                        intent.putExtra("url", "/h5/mLotteryDraw" + "?app=true");
                        intent.putExtra("title", "每日抽奖");
                        intent.putExtra("share", 1);
                        startActivity(intent);

                    }

                } else {
                    if (jsonObject.optString("comment").equals("please login")) {
                        Intent intent = new Intent(HomeActivity_BeiFen.this,
                                V6LoginActivity.class);
                        intent.putExtra("close", 1);
                        startActivity(intent);
                    } else {
                        ToastUtil.showCenterToast(HomeActivity_BeiFen.this,
                                jsonObject.optString("comment"));
                    }
                }

            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(true);
        volleryUtil.execute(HomeActivity_BeiFen.this, Constant.URL
                + "/api/v5/user/accountCenter", "");
    }

    private void userinfo2() {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    Log.e("main", jsonObject.toString());
                    JSONObject json1 = jsonObject.optJSONObject("data");

                    if (!jsonObject.optString("comment").equals("用户不存在")) {
                        if (json1.optInt("unreadRecords") == 0) {
                            tv_unread.setVisibility(View.GONE);
                        } else {
                            if (json1.optInt("unreadRecords") > 99) {
                                tv_unread.setText("..");
                            } else {
                                tv_unread.setText(json1
                                        .optString("unreadRecords"));
                            }
                            tv_unread.setVisibility(View.VISIBLE);
                        }

                    }

                } else {
                    if (jsonObject.optString("comment").equals("please login")) {
                        tv_unread.setVisibility(View.GONE);
                    } else {

                    }
                }

            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(false);
        volleryUtil.execute(HomeActivity_BeiFen.this, Constant.URL
                + "/api/v5/user/accountCenter", "");
    }

    private void fxtest() {
        Intent intent0 = null;

        intent0 = new Intent(HomeActivity_BeiFen.this, WebViewActivity.class);
        intent0.putExtra("url", iconLink + "?app=true&token=");
        // intent0.putExtra("url",
        // "h5/assess/index?showHeader=1"+"?app=true&token=");
        // intent0.putExtra("flag", 1);
        // intent2.putExtra("url",
        // "/h5/messageCenter?app=true&token="+getToken());
        intent0.putExtra("share", 1);
        intent0.putExtra("titleview", 1);
        intent0.putExtra("title", "风险测评");
        startActivity(intent0);


    }

    private void userinfo() {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    Log.e("main", jsonObject.toString());
                    JSONObject json1 = jsonObject.optJSONObject("data");

                    if (!jsonObject.optString("comment").equals("用户不存在")) {

                        if (iconType.equals("1")) {
                            fxtest();
                        } else {
                            mydialog = new Mydialog(HomeActivity_BeiFen.this,
                                    R.style.activity_dialogStyle);
                            View view = getLayoutInflater().inflate(
                                    R.layout.v6_active, null);
                            mydialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                            mydialog.setContentView(view);
                            mydialog.setCanceledOnTouchOutside(true);
                            mydialog.setCancelable(true);

                            homewebview("", view);
                            mydialog.show();
                        }

                    }

                } else {
                    if (jsonObject.optString("comment").equals("please login")) {

                        Intent intent = new Intent(HomeActivity_BeiFen.this,
                                V6LoginActivity.class);
                        intent.putExtra("close", 1);
                        startActivity(intent);

                    } else {
                        Toast.makeText(HomeActivity_BeiFen.this,
                                jsonObject.optString("comment"), 2000).show();
                    }
                }

            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(true);
        volleryUtil.execute(HomeActivity_BeiFen.this, Constant.URL
                + "/apiAccount/checkAuthentication", "");
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        return false;
    }



    @SuppressLint("HandlerLeak")
    Handler handler = new Handler() {
        public void handleMessage(Message msg) {

            initDate(true);
            sv.onRefreshComplete();
            imageAdapter.notifyDataSetChanged();


        }

        ;
    };


    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent = null;
        switch (v.getId()) {

            case R.id.iv_test:

                break;
            case R.id.img_invate:

                break;
            case R.id.img_left:
                if (page != 0) {
                    home_view_pager.setCurrentItem(page - 1);

                }
                break;
            case R.id.img_right:

                break;
            case R.id.li_info:
                Intent intent3 = new Intent(HomeActivity_BeiFen.this,
                        V4WebViewActivity.class);
                intent3.putExtra("url", "h5/infoList?app=true");

                // intent2.putExtra("url",
                // "/h5/messageCenter?app=true&token="+getToken());
                intent3.putExtra("share", 1);
                intent3.putExtra("title", "新闻公告");
                // intent=new Intent(HomeActivity.this,V6LoginActivity.class);
                // startActivity(intent);
                startActivity(intent3);

                break;
            case R.id.li_safe:
                Intent intent2 = new Intent(HomeActivity_BeiFen.this,
                        WebViewActivity.class);
                intent2.putExtra("url", "landing/knowUd?app=true&token=");


                intent2.putExtra("share", 1);
                intent2.putExtra("titleview", 1);
                intent2.putExtra("title", "了解优点");
                startActivity(intent2);
                break;
            case R.id.li_invate:

                Intent intent1 = new Intent(HomeActivity_BeiFen.this,
                        WebViewActivity.class);
                intent1.putExtra("url", "helpCenter/mzIndex?app=true&fromIndex=true&token=");
                intent1.putExtra("share", 1);
                intent1.putExtra("titleview", 1);
                intent1.putExtra("title", "帮助中心");
                startActivity(intent1);
                break;
            case R.id.img_test:
                userinfo();

                break;
            case R.id.li_lottery:
//			islogin();
                intent = new Intent(HomeActivity_BeiFen.this, WebViewActivity.class);
                intent.putExtra("url", "h5/messageCenter?app=true&token=");
                intent.putExtra("title", "我的消息");
                intent.putExtra("titleview", 1);
                intent.putExtra("share", 1);
                startActivity(intent);
//
                break;
            case R.id.view_dexterty:
                MainActivity.newInstance().setCurrentTabByTag("tab_tag_dextrity");
                break;
            case R.id.view_fresh:
                Intent intent6 = new Intent(HomeActivity_BeiFen.this,
                        V6DetailsActivity.class);

                intent6.putExtra("name", name);
                intent6.putExtra("type", type);

                intent6.putExtra("id", loanid);
                startActivity(intent6);
                break;
            case R.id.li_operation:
                intent = new Intent(HomeActivity_BeiFen.this, V4WebViewActivity.class);
                intent.putExtra("url", "api/operReport?app=true");
                intent.putExtra("title", "运营报告");
                intent.putExtra("share", 1);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void setcurrent() {
        // TODO Auto-generated method stub
        MainActivity.newInstance().setCurrentTabByTag("tab_tag_liebiao");
    }

    public void homewebview(String url, View view) {
        WebView v4_webview;
        v4_webview = (WebView) view.findViewById(R.id.v4_webview);
        rl_web = (RelativeLayout) view.findViewById(R.id.rl_web);
        v4_webview.getSettings().setUseWideViewPort(true);

        v4_webview.getSettings().setLoadWithOverviewMode(true);
        v4_webview.getSettings().setSavePassword(true);
        v4_webview.getSettings().setSaveFormData(true);
        v4_webview.getSettings().setJavaScriptEnabled(true);
        // enable navigator.geolocation
        v4_webview.getSettings().setGeolocationEnabled(true);
        v4_webview.getSettings().setGeolocationDatabasePath(
                "/data/data/org.itri.html5webview/databases/");
        // enable Web Storage: localStorage, sessionStorage
        // v4_webview.getSettings().setDomStorageEnabled(true);
        v4_webview.requestFocus();
        v4_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        // v4_webview.setScrollBarStyle(0);
        String ua = v4_webview.getSettings().getUserAgentString();
        v4_webview.getSettings().setUserAgentString(
                ua + "; " + "rmbbox_android");
        v4_webview.setBackgroundColor(0);
        v4_webview.addJavascriptInterface(new JsInterfaces(this),
                "AndroidWebView");
        v4_webview.getSettings().setBuiltInZoomControls(true);
        v4_webview.getSettings().setLayoutAlgorithm(
                WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        v4_webview.getSettings().setDomStorageEnabled(true);
        // Set cache size to 8 mb by default. should be more than enough
        v4_webview.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
        // if(v4_webview.getX5WebViewExtension()!=null){
        //
        // v4_webview.getX5WebViewExtension().setVerticalScrollBarDrawable(null);
        // }
        // This next one is crazy. It's the DEFAULT location for your app's
        // cache
        // But it didn't work for me without this line.
        // UPDATE: no hardcoded path. Thanks to Kevin Hawkins
        String appCachePath = getApplicationContext().getCacheDir()
                .getAbsolutePath();

        v4_webview.getSettings().setAllowFileAccess(true);
        v4_webview.getSettings().setAppCacheEnabled(true);
        v4_webview.getSettings().setJavaScriptEnabled(true);
        v4_webview.getSettings().setAppCachePath(appCachePath);
        v4_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        v4_webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//		v4_webview.getSettings().setSupportZoom(true);
        v4_webview.getSettings().setDefaultTextEncodingName("utf-8");
        v4_webview.loadUrl(Constant.URL + iconLink + "?app=true&token="
                + getToken());
        LogUtils.e(HomeActivity_BeiFen.this, Constant.URL + iconLink + "?app=true&token="
                + getToken());
        setdisappear_bottom_in(HomeActivity_BeiFen.this, rl_web);
        v4_webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String arg1) {
                // TODO Auto-generated method stub
                view.loadUrl(arg1);
                return true;
            }

            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view,
                                                              String url) {
                // TODO Auto-generated method stub
                WebResourceResponse response = null;
                Log.e("url", url);
                response = super.shouldInterceptRequest(view, url);
                if (url.contains("redPacket2016-banner.png")) {
                    try {
                        String murl = url.substring(url.lastIndexOf("/") + 1,
                                url.length());
                        Log.e("css", murl);
                        response = new WebResourceResponse("image/png",
                                "UTF-8", getAssets().open(murl));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                return response;
            }

            @Override
            public void onReceivedError(WebView view, int errorCode,
                                        String description, String failingUrl) {
                // TODO Auto-generated method stub
                super.onReceivedError(view, errorCode, description, failingUrl);
            }

//			@Override
//			public void onReceivedSslError(WebView view,
//					SslErrorHandler handler, SslError error) {
//				// TODO Auto-generated method stub
//				// super.onReceivedSslError(view, handler, error);
//				handler.proceed();
//			}

            @Override
            public void onReceivedSslError(WebView arg0, SslErrorHandler arg1,
                                           com.tencent.smtt.export.external.interfaces.SslError arg2) {
                // TODO Auto-generated method stub
//				super.onReceivedSslError(arg0, arg1, arg2);
                arg1.proceed();
            }

            @Override
            public void onPageFinished(WebView view, String arg1) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, arg1);
                // if(rl_web!=null){
                //
                // rl_web.setBackgroundColor(Color.parseColor("#4c000000"));
                // }
            }
        });

    }

    Handler handler2 = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            super.handleMessage(msg);
            if (msg.what == 0) {
                countdwon();


            }
        }
    };

    private void countdwon() {
        if (minute == 0) {
            if (second == 0) {

                if (hour == 0) {
                    if (timer != null) {
                        timer.cancel();
                        timer = null;
                    }
                    if (timerTask != null) {
                        timerTask = null;
                    }
                    li_close_all.setVisibility(View.GONE);
                    tv_zhitou_status.setBackgroundResource(R.drawable.bianqian);
                    tv_zhitou_status.setText("可投资");
                } else {


                }

            } else {
                second--;
                if (second == 0) {
                    if (hour != 0) {
                        hour--;
                        second = 59;
                        minute = 59;
                    }
                }
                if (hour > 10) {
                    tv_v6_productdetails_hour.setText(hour + "");

                } else {
                    // timeView.setText("0"+minute + ":0" + second);
                    tv_v6_productdetails_hour.setText("0" + hour);

                }
                if (second >= 10) {
                    // timeView.setText("0"+minute + ":" + second);
                    tv_v6_productdetails_min.setText("0" + minute);
                    tv_v6_productdetails_second.setText(second + "");
                } else {
                    // timeView.setText("0"+minute + ":0" + second);
                    tv_v6_productdetails_min.setText("0" + minute);
                    tv_v6_productdetails_second.setText("0" + second);
                }
            }
        } else {
            if (second == 0) {
                second = 59;
                minute--;
                if (minute >= 10) {
                    // timeView.setText(minute + ":" + second);
                    tv_v6_productdetails_min.setText(minute + "");
                    tv_v6_productdetails_second.setText(second + "");
                } else {
                    // timeView.setText("0"+minute + ":" + second);
                    tv_v6_productdetails_min.setText("0" + minute);
                    tv_v6_productdetails_second.setText(second + "");
                }
            } else {
                second--;
                if (second >= 10) {
                    if (minute >= 10) {
                        // timeView.setText(minute + ":" + second);
                        tv_v6_productdetails_min.setText(minute
                                + "");
                        tv_v6_productdetails_second
                                .setText(second + "");
                    } else {
                        // timeView.setText("0"+minute + ":" + second);
                        tv_v6_productdetails_min.setText("0"
                                + minute);
                        tv_v6_productdetails_second
                                .setText(second + "");
                    }
                } else {
                    if (minute >= 10) {
                        // timeView.setText(minute + ":0" + second);
                        tv_v6_productdetails_min.setText(minute
                                + "");
                        tv_v6_productdetails_second.setText("0"
                                + second);
                    } else {
                        // timeView.setText("0"+minute + ":0" + second);
                        tv_v6_productdetails_min.setText("0"
                                + minute);
                        tv_v6_productdetails_second.setText("0"
                                + second);

                    }
                }
            }
        }
    }

    private void countdwoninit(long time) {
        long keyong = time;
//	btn.setBackgroundResource(R.drawable.my_button);
//	btn.setText("马上投资");
//	checkBox.setEnabled(true);
        long day = keyong / (24 * 60 * 60 * 1000);
        long hour = (keyong / (60 * 60 * 1000) - day * 24);
        long min = ((keyong / (60 * 1000)) - day * 24 * 60 - hour * 60);
//	long min = 20;
        @SuppressWarnings("unused")
        long s = (keyong / 1000 - day * 24 * 60 * 60 - hour
                * 60 * 60 - min * 60);
//	long s=10;
        // long ms = (keyong - day * 24 * 60 * 60 * 1000 - hour*
        // 60 * 60 * 1000 - min * 60 * 1000 - s * 1000);
        // System.out.println(day + "天" + hour + "小时" + min +
        // "分"+ s + "秒" + ms + "毫秒");

        if (hour >= 10) {
            tv_v6_productdetails_hour.setText(hour + "");
        } else {
            tv_v6_productdetails_hour.setText("0" + hour);
        }

        tv_v6_productdetails_min.setText(min + "");
        tv_v6_productdetails_second.setText("" + s);
        this.hour = hour;
        minute = min;
        second = s;
        timerTask = new TimerTask() {

            @Override
            public void run() {
                Message msg = new Message();
                msg.what = 0;
                handler2.sendMessage(msg);
            }
        };

        if (timer == null) {

            timer = new Timer();
            timer.schedule(timerTask, 0, 1000);
        }
    }

    private class JsInterfaces {
        private Context mContext;

        public JsInterfaces(Context context) {
            this.mContext = context;
        }

        @JavascriptInterface
        public void dissmis() {
            if (mydialog != null) {

                mydialog.dismiss();
            }
        }

        @JavascriptInterface
        public void pleaseLogin(String name) {
            Intent intent = new Intent(HomeActivity_BeiFen.this, V6LoginActivity.class);
            intent.putExtra("close", 1);

            startActivityForResult(intent, 1);

        }

        @JavascriptInterface
        public void showInfoFromJs(String name) {

        }

        @JavascriptInterface
        public void toproduct(String[] list) {

            // Toast.makeText(Active_Webview.this, list.toString(),
            // 2000).show();

            Intent intent = new Intent(HomeActivity_BeiFen.this,
                    V6DetailsActivity.class);
            intent.putExtra("flag", Boolean.parseBoolean(list[0]));
            intent.putExtra("name", list[1]);
            intent.putExtra("type", list[2]);
            intent.putExtra("id", list[3]);
            intent.putExtra("isred", list[4]);
            startActivity(intent);
        }

        @JavascriptInterface
        public void switchpage(String name) {

            if (name.equals("red")) {
                Intent intent = new Intent(HomeActivity_BeiFen.this, MyHongBao.class);
                startActivity(intent);
            } else if (name.equals("exp")) {
                Intent intent = new Intent(HomeActivity_BeiFen.this,
                        MyExperienceGold.class);
                startActivity(intent);
            }
        }

        @JavascriptInterface
        public void jsshare(String sharelink, String description, String title) {
            // Toast.makeText(V4WebViewActivity.this, sharelink+sharelink+title,
            // 2000).show();
            // if(sharelink.length()>1){
            // shareforjs(sharelink, description, title);
            //
            // }
        }

        @JavascriptInterface
        public void switchActive() {
            active();
        }

        @JavascriptInterface
        public void settab(final int i) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    Editor ed = getShare().edit();
                    ed.putInt("tab", i);
                    ed.commit();
                    mydialog.dismiss();
                    Log.e("tab", i + "");
                    MainActivity.newInstance().setCurrentTabByTag(
                            "tab_tag_liebiao");
                }
            });

            // Intent intent = new Intent(HomeActivity.this,
            // MainActivity.class);
            // intent.putExtra("licai", 1);
            // startActivity(intent);
        }

        @JavascriptInterface
        public void setTitle(String title) {

        }

        @JavascriptInterface
        public void setMusicStatus(boolean flag) {
            Editor ed = getShare().edit();
            ed.putBoolean("music", flag);
            ed.commit();
            Log.e("setmusic", "" + flag);

        }

        @JavascriptInterface
        public void setactivity(String activity) {

            Intent intent;
            try {
                intent = new Intent(HomeActivity_BeiFen.this, Class.forName(activity));
                startActivity(intent);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    }

    @Override
    public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
        // TODO Auto-generated method stub
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                handler.sendEmptyMessage(1);
            }
        }, 2000);

    }


}
